package com.wsp.controllermanagement.security;

import com.wsp.controllermanagement.Util.BcrypUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.springframework.stereotype.Component;

/**
 * Package: com.wsp.controllermanagement.security
 * Description： TODO
 *
 * @Author: 巫思平
 * Copyright: Copyright (c) 2020
 * Version: 1
 */
@Component
public class SecurityMatcher extends SimpleCredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        //前端传来的密码
        UsernamePasswordToken admin = (UsernamePasswordToken) token;
        String password = new String(admin.getPassword());
        //数据库中查询出的加密后的密码
        String encodePassword = (String) info.getCredentials();
        //密码比较
        return BcrypUtil.match(password, encodePassword);
    }
}
